package org.jc.subject.common.entity;

import lombok.Data;

import java.util.Collections;
import java.util.List;

/**
 * 功能描述
 *
 * @author wanghongqian
 * @date 2024/06/25 16:07
 */
@Data
public class PageResult<T> {


    private Integer pageNo = 1;

    private Integer pageSize = 20;

    private Integer total = 0;

    private Integer totalPages = 0;

    private List<T> result = Collections.emptyList();

    private Integer start = 1;

    private Integer end = 0;

    public void setRecords(List<T> result){
        this.result = result;
    }

    public void setTotal(Integer total){
        this.total = total;
        if(this.pageSize > 0){
            this.totalPages = (total / this.pageSize) + (total % this.pageSize == 0 ? 0:1);
        }else{
            this.totalPages = 0;
        }

        this.start = (this.pageSize > 0 ? (this.pageNo - 1) * this.pageSize : 0) + 1;
        this.end = (this.start + (this.pageNo > 0 ? 1:0) * pageSize - 1);
    }

    public void setPageNo(Integer pageNo){
        this.pageNo = pageNo;
    }

    public void setPageSize(Integer pageSize){
        this.pageSize = pageSize;
    }

}
